import java.security.Security;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

@SuppressWarnings("restriction")
public class SendMail extends Thread{

private static final String SMTP_HOST_NAME = "smtp.gmail.com";
private static final String SMTP_PORT = "465";
private static final String emailSubjectTxt = "Changed Password in Org.Anize";
private static final String emailFromAddress = "org.anizer6606@gmail.com";
private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
private String UserEmail=null;
private String user=null;

public SendMail(String Info, String User) {
	super("Send Mail Thread");
	this.UserEmail=Info;
	this.user=User;
}


public void run()
 {
String message=null, from, recipient, subject;
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

try {
	boolean debug = false;

	Properties props = new Properties();
	props.put("mail.smtp.host", SMTP_HOST_NAME);
	props.put("mail.smtp.auth", "true");
	props.put("mail.debug", "false");
	props.put("mail.smtp.port", SMTP_PORT);
	props.put("mail.smtp.socketFactory.port", SMTP_PORT);
	props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
	props.put("mail.smtp.socketFactory.fallback", "false");

	from = emailFromAddress;
	recipient= UserEmail;
	subject=emailSubjectTxt;
	
	Session session = Session.getDefaultInstance(props,
	new javax.mail.Authenticator() {

	protected PasswordAuthentication getPasswordAuthentication() {
	return new PasswordAuthentication("org.anizer6606", "adminadmin");
	}
	});

	session.setDebug(debug);
	
	Message msg = new MimeMessage(session);
	InternetAddress addressFrom = new InternetAddress(from);
	msg.setFrom(addressFrom);

	InternetAddress addressTo = new InternetAddress(recipient);

	msg.setRecipient(Message.RecipientType.TO, addressTo);

	message= "Dear " + user + ",\n\nThe Following Email has been sent by the Org.Anize software as per your " +
			"request to change your password.\nYour New Password now is:\n" + "qwrty1234" + "\n\n**Please do not forget to change your password immediatly after you login**\n\nThank you...\n\nBest Regards,\nOrg.Anizer Administrator";

	msg.setSubject(subject);
	msg.setContent(message, "text/plain");
	Transport.send(msg);
	

} 
catch (MessagingException e) 
{

	e.printStackTrace();

 }
 }
}

